package tests;

import gameComponents.Player;
import gamePieces.Queen;

import java.awt.Point;
import java.util.ArrayList;

import junit.framework.TestCase;

/**
 * 
 */

/**
 * @author SELMAN
 *
 */
public class QueenTest extends TestCase {

	Player p = new Player(1);
	Queen q = new Queen(0,0,p);
	/**
	 * @param name
	 */
	public QueenTest(String name) {
		super(name);
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
	}

	/**
	 * Test method for {@link Queen#checkIfLegal(int, int)}.
	 * @author Selman Selman
	 */
	public final void testCheckIfLegal() {
		//check if checkIfLegal would return true if queen moves one forward
		assertTrue(q.checkIfLegal(0,1));
		//check if checkIfLegal would return true if queen moves 2 forward
		assertTrue(q.checkIfLegal(0, 2));
		//check if checkIfLegal would return true if queen moves horizontally
		assertTrue(q.checkIfLegal(1, 0));
		//check if checkIfLegal would return true if queen moves diagonally
		assertTrue(q.checkIfLegal(1, 1));	
		//checks if checkIfLegal would return false if queen moves out of boundaries
		assertFalse(q.checkIfLegal(10, 10));
		
	}

	/**
	 * Test method for {@link Piece#getX()}.
	 * @author Selman Selman
	 */
	public final void testGetX() {
		//since pawn is created initially at (0,0)
		//getX() should return 0
		assertEquals(q.getX(),0);
	}

	/**
	 * Test method for {@link Piece#getY()}.
	 * @author Selman Selman
	 */
	public final void testGetY() {
		//since pawn is created initially at (0,0)
		//getY() should return 0
		assertEquals(q.getY(),0);
	}

	/**
	 * Test method for {@link Piece#setX(int)}.
	 * @author Selman Selman
	 */
	public final void testSetX() {
		q.setX(1); // set x coordinate to 1
		//check that x is now 1
		assertEquals(q.getX(),1);
	}

	/**
	 * Test method for {@link Piece#getOwnership()}.
	 * @author Selman Selman
	 */
	public final void testGetOwnership() {
		//get Ownership should return object p
		assertEquals(q.getOwnership(),p);
	}

	/**
	 * Test method for {@link Piece#setY(int)}.
	 * @author Selman Selman
	 */
	public final void testSetY() {
		q.setY(1); // set y coordinate to 1
		//check that y is now 1
		assertEquals(q.getY(),1);
	}

	/**
	 * Test method for {@link Piece#getMoves()}.
	 * @author Selman Selman
	 */
	public final void testGetMoves() {
		q.possibleMoves();
		ArrayList<Point> p = q.getMoves();
		for(int i = 1; i<8; i++){ //makes sure diagonal moves are included in array
			assertTrue(p.contains(new Point(i,i)));
		}
		for(int i = 1; i<8; i++){ //makes sure vertical moves are included in array
			assertTrue(p.contains(new Point(0,i)));
		}
		for(int i = 1; i<8; i++){ //makes sure horizontal moves are included in array
			assertTrue(p.contains(new Point(i,0)));
		}
		
	}

	/**
	 * Test method for {@link Piece#move(int, int)}.
	 * @author Selman Selman
	 */
	public final void testMove() {
		//checks if queen will move 2 forward 
		q.move(0,2);
		assertEquals(q.getX(),0);
		assertEquals(q.getY(), 2);
		
		//new x and y coordinates are 0 and 2 respectively 
		//check if queen will move 1 forward
		q.move(0,3); // knight should not move
		assertEquals(q.getX(),0);
		assertEquals(q.getY(),3);
		
		//checks if queen will move  diagonally
		q.move(1,4);
		assertEquals(q.getX(),1);
		assertEquals(q.getY(),4);
		//move queen out of boundaries
		q.move(9,9); //queen should not move
		assertEquals(q.getX(),1);
		assertEquals(q.getY(),4);
	}

}
